Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AWS MSK cluster resource #8635

Merged
merged 4 commits into from
May 22, 2019
Merged

Add AWS MSK cluster resource #8635

merged 4 commits into from
May 22, 2019

Conversation

jesseaukeman
Copy link
Contributor

This is a new implementation of the AWS MSK cluster resource.

I realize this overlaps and duplicates #8357. This was a separate and parallel effort undertaken for the company I work for. I apologize if this is bad form, however I think this effort is a bit further along, as the other effort may be stalled on acceptance tests.

  • implement aws_msk_cluster resource with support for tags
  • implement acceptance tests

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

Fixes #6653
Fixes #8429

Release note for CHANGELOG:


Output from acceptance testing:

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSMskCluster'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -parallel 20 -run=TestAccAWSMskCluster -timeout 120m
=== RUN   TestAccAWSMskCluster_basic
=== PAUSE TestAccAWSMskCluster_basic
=== RUN   TestAccAWSMskCluster_kms
=== PAUSE TestAccAWSMskCluster_kms
=== RUN   TestAccAWSMskCluster_enhancedMonitoring
=== PAUSE TestAccAWSMskCluster_enhancedMonitoring
=== RUN   TestAccAWSMskCluster_tagsUpdate
=== PAUSE TestAccAWSMskCluster_tagsUpdate
=== RUN   TestAccAWSMskCluster_brokerNodes
=== PAUSE TestAccAWSMskCluster_brokerNodes
=== CONT  TestAccAWSMskCluster_basic
=== CONT  TestAccAWSMskCluster_tagsUpdate
=== CONT  TestAccAWSMskCluster_kms
=== CONT  TestAccAWSMskCluster_brokerNodes
=== CONT  TestAccAWSMskCluster_enhancedMonitoring
--- PASS: TestAccAWSMskCluster_enhancedMonitoring (958.48s)
--- PASS: TestAccAWSMskCluster_kms (1062.45s)
--- PASS: TestAccAWSMskCluster_basic (1063.50s)
--- PASS: TestAccAWSMskCluster_brokerNodes (1096.43s)
--- PASS: TestAccAWSMskCluster_tagsUpdate (1130.02s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       1130.671s
...

* implement aws_msk_cluster resource with support for tags
* implement acceptance tests
@ghost ghost added size/XXL Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. provider Pertains to the provider itself, rather than any interaction with AWS. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels May 14, 2019
@dthtvwls dthtvwls mentioned this pull request May 15, 2019
@KellerII
Copy link

Any idea on when this will be ready/merged?

@bflad bflad added new-resource Introduces a new resource. service/kafka Issues and PRs that pertain to the kafka service. labels May 22, 2019
@bflad bflad self-assigned this May 22, 2019
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jesseaukeman 👋 Thanks so much for this contribution! It was in great shape. I left some feedback notes below during review but in the interest of getting this resource (and potentially a new resource for managing MSK Configurations) released this week, we handled the items in a followup commit (7cb443c). Thanks again, this will make a bunch of people happy. 🚀

Output from acceptance testing:

--- PASS: TestAccAWSMskCluster_basic (987.37s)
--- PASS: TestAccAWSMskCluster_tagsUpdate (999.03s)
--- PASS: TestAccAWSMskCluster_enhancedMonitoring (1018.97s)
--- PASS: TestAccAWSMskCluster_kms (1042.61s)
--- PASS: TestAccAWSMskCluster_brokerNodes (1074.66s)

info := v.([]interface{})
if len(info) == 1 {
if info[0] == nil {
return fmt.Errorf("At least one item is expected inside encryption_info")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of returning an error here, we should be able to just move the nil check up a line and only include the EncryptionInfo then. 👍

out, err = conn.CreateCluster(input)

if err != nil {
if isAWSErr(err, kafka.ErrCodeTooManyRequestsException, "Too Many Requests") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than introducing resource.Retry() logic, which is missing a isResourceTimeoutError(err) check below (context: #7873), we should move this error code into our SDK client logic to automatically have the SDK retry these requests.

Examples of this code can be found here:

https://github.com/terraform-providers/terraform-provider-aws/blob/bdcf6a2e2fa396a09bd63fb1ce354398f89244aa/aws/config.go#L539-L544

An example implementation for here:

	client.kafkaconn.Handlers.Retry.PushBack(func(r *request.Request) {
		if isAWSErr(r.Error, kafka.ErrCodeTooManyRequestsException, "Too Many Requests") {
			r.Retryable = aws.Bool(true)
		}
	})

We should likely also submit this upstream to the AWS Go SDK to automatically retry and throttle these as well.

return resourceAwsMskClusterRead(d, meta)
}

func waitForClusterCreation(conn *kafka.Kafka, arn string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Since this project currently uses a very flat Go package structure, we should include the service name in the function name here to delineate which type of cluster we are referring to:

Suggested change
func waitForClusterCreation(conn *kafka.Kafka, arn string) error {
func waitForMskClusterCreation(conn *kafka.Kafka, arn string) error {

return err
}

d.Set("tags", tagsToMapMskCluster(tags))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two notes:

  • The tags value is coming from the configuration above with d.Get(), which makes this call extraneous as Terraform will automatically pass through configuration information into the Terraform state. More importantly though, this information should be read back from the API to ensure it was properly configured in the API.
  • Setting information into the Terraform state should preferably happen during the Read function

Since the Read function does correctly call d.Set() via reading the information from the API for this attribute and the Create function correctly returns the Read function, this is extraneous. 😄

d.Set("arn", aws.StringValue(cluster.ClusterArn))
d.Set("bootstrap_brokers", brokerOut.BootstrapBrokerString)

d.Set("broker_node_group_info", flattenMskBrokerNodeGroupInfo(cluster.BrokerNodeGroupInfo))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using d.Set() with aggregate types (TypeList, TypeSet, TypeMap), we should perform error checking to prevent issues where the code is not properly able to set the Terraform state. e.g.

Suggested change
d.Set("broker_node_group_info", flattenMskBrokerNodeGroupInfo(cluster.BrokerNodeGroupInfo))
if err := d.Set("broker_node_group_info", flattenMskBrokerNodeGroupInfo(cluster.BrokerNodeGroupInfo)); err != nil {
return fmt.Errorf("error setting broker_node_group_info: %s", err)
}

Terraform resource for managing an AWS Managed Streaming for Kafka cluster
---

# aws_msk_cluster
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We're now including Resource: in resource titles 👍

Suggested change
# aws_msk_cluster
# Resource: aws_msk_cluster

# aws_msk_cluster

Manages AWS Managed Streaming for Kafka cluster

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintainer Note: Adding the preview callout for this resource documentation

~> NOTE: This AWS service is in Preview and may change before General Availability release. Backwards compatibility is not guaranteed between Terraform AWS Provider releases.

@@ -1876,6 +1876,16 @@
</ul>
</li>

<li>
<a href="#">MSK Resources</a>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'm thinking we might want to call out the full name here for folks searching for just "kafka", e.g.

Suggested change
<a href="#">MSK Resources</a>
<a href="#">Managed Streaming for Kafka (MSK) Resources</a>

MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"encryption_at_rest_kms_id": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the API always returns the ARN, we should just require inputting the ARN here to simplify attribute handling (removing the DiffSuppressFunc) and prevent potential "inconsistent plan" errors in Terraform 0.12 (the new "diffs didn't match during apply" error from Terraform 0.11).

Suggested change
"encryption_at_rest_kms_id": {
"encryption_at_rest_kms_key_arn": {

State: schema.ImportStatePassthrough,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(45 * time.Minute),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears these customizable timeouts are not passed into the waiter functions (e.g. waitForMskClusterCreation) so they should be removed. 👍

@bflad bflad added this to the v2.12.0 milestone May 22, 2019
@bflad bflad merged commit 285c515 into hashicorp:master May 22, 2019
bflad added a commit that referenced this pull request May 22, 2019
Reference: #8635

Output from acceptance testing:

```
--- PASS: TestAccAWSMskCluster_basic (987.37s)
--- PASS: TestAccAWSMskCluster_tagsUpdate (999.03s)
--- PASS: TestAccAWSMskCluster_enhancedMonitoring (1018.97s)
--- PASS: TestAccAWSMskCluster_kms (1042.61s)
--- PASS: TestAccAWSMskCluster_brokerNodes (1074.66s)
```
bflad added a commit that referenced this pull request May 22, 2019
@bflad bflad mentioned this pull request May 22, 2019
2 tasks
@bflad
Copy link
Contributor

bflad commented May 24, 2019

This has been released in version 2.12.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Mar 29, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. new-resource Introduces a new resource. provider Pertains to the provider itself, rather than any interaction with AWS. service/kafka Issues and PRs that pertain to the kafka service. size/XXL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Amazon MSK tagging Feature Request: Managed Streaming for Kafka
3 participants